﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DebugTools
{
    public class PowerMeter:Visa
    {
        public string _szType;

        public List<String> _ListInitCmd;
        protected string _szCmd;
        protected string _szRet;

        public double _dVolt;
        public double _dCurr;
        public double _dPow;

        public PowerMeter(string szInsID):base(szInsID)
        {
            _ListInitCmd = new List<String>();
            _szType = "xxxx";
        }

        public virtual bool Init()
        {
            bool bRet = this.QueryType().Contains(_szType);
            if(bRet)
            {
                if(_ListInitCmd.Count > 0)
                {
                    for(int i = 0; i < _ListInitCmd.Count; i++)
                    {
                        _szCmd = _ListInitCmd[i];
                        this.Write(_szCmd);
                    }
                }
            }

            return bRet;
        }

        public virtual double Meas_Volt()
        {
            _dVolt = 0.0;
            this.Clean();
            //szCmd = "MEAS:VOLT:RMS?\n";
            _szRet = this.Query(_szCmd);

            double.TryParse(_szRet, out _dVolt);
            return _dVolt;
        }

        public virtual double Meas_Curr()
        {
            _dCurr = 0.0;
            this.Clean();
            //szCmd = "MEAS:CURR:RMS?\n";
            _szRet = this.Query(_szCmd);
            //截取返回值

            double.TryParse(_szRet, out _dCurr);
            return _dCurr;
        }

        public virtual double Meas_Power()
        {
            _dPow = 0.0;
            this.Clean();
            //szCmd = "MEAS:POW:REAL?\n";
            _szRet = this.Query(_szCmd);
            //截取返回值

            double.TryParse(_szRet, out _dPow);
            return _dPow;
        }
    }
}
